--
-- Author: shunguo.chen
-- Date: 2017-09-11 11:56:12
--
-- ZoneListRender	服务器目录

local ClassRef = app.mvc.createRenderClass(...)

--data = {tag=1, name="1-10"}
function ClassRef.create(data, node)
	local sprite = ClassRef.extend(node or cc.CSLoader:createNode(Res.LoginZoneNode1))
	if node == nil then
		ccui.Helper:doLayout(sprite)
	end
	sprite:init(data)
	return sprite
end

function ClassRef:init(data)
	self.super.init(self, data)

	self:setContentSize(self._ui.Panel:getContentSize())

	-- btns
	self._ui.Button_bg:setPressedActionEnabled(false)
	self._ui.Button_bg:addClickEventListener(function()
		if self._data and not self:isSelected() then
			executeFunc(self._onBtnClick, self)
		end
	end)

	self:setSelected(false)

	self:refresh()
end

function ClassRef:refresh()
	if self._data then
		self._ui.name:setString(self._data.name)
	end
end

function ClassRef:getName()
	if self._data then
		return self._data.name
	end 
end

function ClassRef:onBtnClick(cb)
	self._onBtnClick = cb
end

function ClassRef:isSelected()
	return not self._ui.Button_bg:isBright()
end
function ClassRef:setSelected(b)
	self._ui.Button_bg:setBright(not b)
	self._ui.name:setColor(b and cc.c3b(255, 225, 132) or cc.c3b(98, 98, 98))
end

return ClassRef